import pandas as pd
from sklearn.ensemble import AdaBoostClassifier
"""
此程序使用的是自适应增强的算法，调用了sklearn中的AdaBoostClassifier
得到的精度和AUC相比于随机森林都有小幅的下降，但整体的结果还属于较好的水平
"""
# read data from the file
train = pd.read_csv("data/train.csv")
test = pd.read_csv("data/test.csv")
submit = pd.read_csv("data/sample_submit.csv")

# delete id
train.drop('CaseId', axis=1, inplace=True)
test.drop('CaseId', axis=1, inplace=True)

# extract y from train set
y_train=train.pop('Evaluation')

# Using AdaBoostClassifier to classify
clf=AdaBoostClassifier(n_estimators=100,random_state=0)
clf.fit(train,y_train)
y_pred=clf.predict_proba(test)[:,1]
y_train_pred=clf.predict(train)

# output predictive results to csv files
submit['Evaluation']=y_pred
submit.to_csv('my_AdaBoost_prediction.csv',index=False)

print("Feature importances and predictions of AdaBoost")
print(clf.feature_importances_)
print(y_train_pred)

# Prediction evaluations
# Using accuracy and AUC respectively
from sklearn.metrics import accuracy_score
from sklearn.metrics import roc_auc_score

acc_train=accuracy_score(y_train,y_train_pred)
print("acc_train = %f" % (acc_train))
auc_train=roc_auc_score(y_train,y_train_pred)
print("auc_train = %f" % (auc_train))